home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / progem.lzh / wind10.prf < prev    next >
Encoding:
Text File  |  1987-06-23  |  12.9 KB  |  300 lines

  1. .!****************************************************************************
  2. .! 
  3. .! ANTIC PUBLISHING INC., COPYRIGHT 1985.  REPRINTED BY PERMISSION.
  4. .!
  5. .! ** Professional GEM ** by Tim Oren
  6. .!
  7. .! Proff File by ST enthusiasts at
  8. .! Case Western Reserve University
  9. .! Cleveland, Ohio
  10. .! uucp : decvax!cwruecmp!bammi
  11. .! csnet: bammi@case
  12. .! arpa : bammi%case@csnet-relay
  13. .! compuserve: 71515,155
  14. .!
  15. .!****************************************************************************
  16. .!
  17. .!
  18. .!****************************************************************************
  19. .!
  20. .!            Begin Part 10
  21. .!
  22. .!****************************************************************************
  23. .!
  24. .PART X VDI Graphics: Text Output
  25. .PP
  26. This  issue of ST PRO GEM concludes the two column series  on
  27. VDI  with a look at simple VDI  text output,  and ways to optimize
  28. its  speed.   There is also a Feedback section.   You may find the
  29. associated  download  file under the name GMCL10.C in DL3  of  the
  30. ATARI16 SIG (PCS-58).
  31. .PP
  32. To  keep  the size of this first discussion  of  text  within
  33. reason, I am going to restrict it to use of the mono-spaced system
  34. font   in  its  default  size  and  orientation.    Discussion  of
  35. alternate and proportionally spaced fonts,  baseline rotation, and
  36. character scaling will become a later article in this series.
  37. .SH DEFINITIONS
  38. This  article  makes use of  some  terminology
  39. which may be unfamiliar if you have not used digital typefaces.  A
  40. mono-spaced  font  is  one in which  each  character  occupies  an
  41. identically  wide  space on the screen.   A proportional font  has
  42. characters  which occupy different widths.   For instance,  an 'l'
  43. would probably be narrower than a 'w'.
  44. .PP
  45. Text may be "justified" right,  left,  or center.  This means
  46. that  the right character,  left character,  or center position of
  47. the  text  string is constrained to a given location.   In  common
  48. usage,  a  page  of text is "ragged right" if its lines  are  left
  49. justified only.   The text page is "fully justified",  "justified"
  50. or  (ambiguously)  "right justified" if BOTH the  left  and  right
  51. characters are contrained to fixed columns.  Full justification is
  52. produced  by  inserting extra blank characters in the  case  of  a
  53. mono-spaced font,  or by adding extra pixel columns in the case of
  54. proportional output.
  55. .PP
  56. A  text character (in a monospaced font) is written inside  a
  57. standard sized cell or box.  Vertically, the cell extends from the
  58. "top  line" down to the "bottom line".   If there are one or  more
  59. blank  lines at the top or bottom,  they are called "leading"  and
  60. are  used  to separate lines of text.   The characters  themselves
  61. always  fall between the "ascent line",  which is the highest line
  62. reached by characters such as 'd' and 'l', and the "descent line",
  63. which  is the lowest line in characters like 'q' and  'g'.   Other
  64. locations  of  interest are the "half line",  which is the top  of
  65. characters  like  'a' or 'n',  and the "base line",  which is  the
  66. bottom of characters which do not have descenders.
  67. .PP
  68. Before  plunging into the Attribute Functions for  text,  you
  69. should  note  that  the  writing  mode  (vswr_mode)  and  clipping
  70. rectangle  (vs_clip) attributes discussed in the last column  (#9)
  71. also  pertain  to  text.   Since much of the  discussion  of  text
  72. optimization  will  center on these attributes,  you may  want  to
  73. review them.
  74. .SH TEXT ATTRIBUTES
  75. The writing color for graphics text is set
  76. with the command:
  77. .FB vst_color()
  78.           vst_color(vdi_handle, color);
  79. .FE
  80. Vdi_handle  is  always the handle returned from  graf_handle()  at
  81. application startup.  Color is a word value between 0 and 15 which
  82. designates  the  output  color index.   As discussed  in  previous
  83. columns,  the  actual  color  which appears is  dependent  on  the
  84. current  palette  settings.   In  applications such  as  word  and
  85. outline  processors  it  is important that  characters  and  their
  86. background  provide  good contrast to avoid eyestrain.   In  these
  87. situations,  you  may  want to use the setPalette and/or  setColor
  88. XBIOS  functions  to  force the palette to a  known  state  before
  89. starting the application.
  90. .PP
  91. You  can choose a variety of special output effects for  your
  92. text with the call:
  93. .FB vst_effects()
  94. vst_effects(vdi_handle, effects);
  95. .FE
  96. Effects is a single flag word,  with the bits having the following
  97. significance:
  98. .BO
  99. 0 - Thicken
  100. .EO
  101. .BO
  102. 1 - Lighten
  103. .EO
  104. .BO
  105. 2 - Skew
  106. .EO
  107. .BO
  108. 3 - Underline
  109. .EO
  110. .BO
  111. 4 - Outline
  112. .EO
  113. .BO
  114. 5 - Shadow
  115. .EO
  116. .PP
  117. In each case,  turning the bit on selects the effect.   Otherwise,
  118. the  effect  is  off.   Any  number of  multiple  effects  may  be
  119. selected, but the result may not always be pleasing or legible.
  120. .PP
  121. The  "thicken"  effect widens the character  strokes  by  one
  122. pixel,   resulting  in  the  appearance  of  boldface  type.   The
  123. "lighten" effect superimposes a half-tone dither on the character.
  124. This mode is useful for indicating non-selectable text items,  but
  125. is not legible enough for other purposes.
  126. .PP
  127. The  skew effect shifts the rows of the character the  right,
  128. with  the greatest displacement at the top.   This results in  the
  129. appearance of italic text.   You should be aware that the VDI does
  130. not  compensate for this effect.   This means that a skewed italic
  131. character which is immediately followed by a normal blank will  be
  132. overstruck,  and  part of the top of the character will disappear.
  133. Likewise,  a  skewed character written to the left of an  existing
  134. normal  character will overstrike part of it.   There is a related
  135. bug  in  the VDI clipping logic which may cause some  parts  of  a
  136. skewed  character not to be redrawn if they fall at the edge of  a
  137. clipping  rectangle,  even  though  they should  fall  within  the
  138. region.
  139. .PP
  140. The  outline  effect  produces output which is  a  one  pixel
  141. "halo" around the normal character.  The shadow effect attempts to
  142. create  a  "drop  shadow" to the side  of  the  character.   These
  143. effects  should be used very sparingly with default  sized  fonts.
  144. They often result in illegible output.
  145. .PP
  146. When  graphics text is written,  a screen coordinate must  be
  147. specified  for  the output.   The relationship of the text to  the
  148. screen point is determined by the call:
  149. .FB bst_alignment()
  150.           vst_alignment(vdi_handle, hin, vin, &hout, &vout);
  151. .FE
  152. Hin  and  vin are each words,  with values specifying the  desired
  153. horizontal  and vertical alignment,  respectively.   Hout and vout
  154. receive the actual values set by the VDI.  If they differ from the
  155. requested values, an error has occurred.
  156. .PP
  157. Hin may be set to zero for left justification, one for center
  158. justification,  or  two  for right justification.   The coordinate
  159. given when text is written becomes the "anchor point" as described
  160. in the definitions above.  The default justification is left.
  161. .PP
  162. Vin determines what reference line of the text is  positioned
  163. at the output coordinate.  The selection values are:
  164. .bp
  165. .BO
  166. 0 - baseline (default)
  167. .EO
  168. .BO
  169. 1 - half line
  170. .EO
  171. .BO
  172. 2 - ascent line
  173. .EO
  174. .BO
  175. 3 - bottom line
  176. .EO
  177. .BO
  178. 4 - descent line
  179. .EO
  180. .BO
  181. 5 - top line
  182. .EO
  183. .PP
  184. A  common combination of alignments is left (0) and top  line
  185. (5).   This  mode guarantees that all text output will lie to  the
  186. right and below the output coordinate.   This corresponds with the
  187. AES object and GRECT coordinate systems.
  188. .PP
  189. Finally, the call to do the actual output is:
  190. .FB v_gtext()
  191. v_gtext(vdi_handle, x, y, string);
  192. .FE
  193. X  and y define the screen coordinate to be used as the  alignment
  194. point.   String  is  a pointer to a null terminated string,  which
  195. must  be total eighty characters or less,  exclusive of the  null.
  196. This limit is imposed by the size of the intin[] array in the  VDI
  197. binding.   Be  warned  that  it  is NOT checked  in  the  standard
  198. binding!  Exceeding it may cause memory to be overwritten.
  199. .PP
  200. One Inquire Function is useful with text output.  The call
  201. .FB vqt_attributes()
  202. vqt_attributes(vdi_handle, attrib);
  203. .FE
  204. reads  back the current attribute settings into the 10 word  array
  205. attrib[].   The  main  items  of interest  are  attrib[6]  through
  206. attrib[9],  which contain the width and height of characters,  and
  207. the  width and height of the character cell in the  current  font.
  208. You  should  rely  on this function to  obtain  size  information,
  209. rather  than using the output of the graf_handle()  function.   On
  210. the ST, graf_handle() always returns sizes for the monochrome mode
  211. system font, which will be incorrect in the color screen modes.
  212. .PP
  213. Attrib[1] will contain the current graphics text color as set
  214. by  vst_color().   Attrib[3]  and [4] contain the  horizontal  and
  215. vertical alignment settings, respectively.  Attrib[5] contains the
  216. current writing mode, as set by vswr_mode().
  217. .SH OPTIMIZATION
  218. The most common complaint about using bit maps
  219. for character output is lack of speed.  This section suggests ways
  220. to  speed  things up.   By adopting all of these methods,  you can
  221. realize an improvement of two to three times in speed.
  222. .SH BYTE ALIGNMENT
  223. Since writing graphic text is essentially a
  224. bit-blit operation,  characters which have "fringes",  that is, do
  225. not  align  evenly with byte boundaries,  will suffer  performance
  226. penalities.  The default system fonts in all resolutions of the ST
  227. are  a  multiple of eight pixels wide,  so the problem reduces  to
  228. assuring  that  each characters starts at a byte boundary  in  the
  229. screen bit map.  This will be true if the horizontal pixel address
  230. of the left edge of the character is evenly divisible by eight.
  231. .PP
  232. Obviously,  byte  alignment  is easiest to enforce  when  the
  233. horizontal justification is right or left.  Doing so with centered
  234. text is possible, but requires adding padding blanks to odd length
  235. strings.
  236. .PP
  237. When  writing  text within windows,  it is helpful to  assure
  238. that the edges of the window working area are byte aligned.  There
  239. is  a section of code in the download which shows a technique  for
  240. converting  a  user requested window position and/or size  to  its
  241. working   dimensions,   byte-aligning  the  width  and  horizontal
  242. position, and computing the adjusted external window coordinates.
  243. .SH WRITING MODE
  244. The fastest text output mode is replace.  All
  245. other modes require reading in the target raster area and  merging
  246. it  with  the  new information.   You may find that you  must  use
  247. transparent or reverse transparent mode,  for instance,  to use or
  248. preserve an underlying background color other than white.  In this
  249. case,  you  can  still  do  some optimization by  filling  in  the
  250. background color for the entire string with a v_bar() call, rather
  251. than doing it one character cell at a time.
  252. .SH CLIPPING
  253. VDI  output  always  proceeds  faster  when  the
  254. clipping rectangle is turned off, and text output is no exception.
  255. Remember  that  you  may only do this if you are  drawing  into  a
  256. dialog box,  or into the interior of a window which you know is on
  257. top.   (You  can  use  the WM_TOPPED and  WM_NEWTOP  messages  for
  258. keeping track of the top window, or use the WF_TOP wind_get() call
  259. to  find the current top.)  In both of these cases,  you will know
  260. the  width  of the drawing area,  and you can truncate the  output
  261. string to fit exactly, rather than setting the clipping rectangle.
  262. For this to work,  you must have used the byte alignment technique
  263. to  assure  that the width of the writing area is  a  multiple  of
  264. eight.
  265. .SH BINDINGS
  266. The  normal binding for v_gtext() is inefficient.
  267. It copies the string which you supply character-by-character  into
  268. intin[] before it calls the VDI itself.  In many cases, it will be
  269. more  efficient for your application to place characters  directly
  270. into  intin[] and make the VDI trap call directly.   To give you a
  271. start,  the  code  for  the standard v_gtext()  binding  has  been
  272. included in the download.  When setting up intin[], be sure not to
  273. load  more  than  80 characters,  or you will probably  crash  the
  274. system!
  275. .SH MOVING TEXT
  276. When performing text editing on the screen, you
  277. should  avoid rewriting the string under edit  whenever  possible.
  278. It is always more efficient to use the raster operations to move a
  279. string  to  the right or left,  assuming that you have obeyed  the
  280. byte  alignment rule.    If you are deleting characters,  blit the
  281. unchanged part of the screen to the left,  and overstrike the last
  282. character  in the string with a blank.   If inserting  characters,
  283. blit  the  trailing  portion of the string  to  the  right  before
  284. writing in the new character.
  285. .SH THAT'S IT FOR NOW
  286. This concludes the two article series on
  287. simple  VDI output.   Future columns may explore more complex  VDI
  288. topics such as proportional text.  If there is something you would
  289. like  to  see,  please  use the Online Feedback to  let  me  know!
  290. Meanwhile,  the next column will give out the locations of some of
  291. the  "hooks" and "trapdoors" built into the AES object  structure,
  292. including  how  to set up user-defined AES drawing  objects.
  293. .!
  294. .!
  295. .!*****************************************************************************
  296. .!*                                          *
  297. .!*                End Part 10                      *
  298. .!*                                          *
  299. .!*****************************************************************************
  300.